<template>
  <editTableNew
    :hideBtn="hideBtn"
    :tableSetting="preparaTable"
    ref="preparaTable"
  ></editTableNew>
</template>

<script>
export default {
  props: {
    userConfig: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      hideBtn: false,
      preparaTable: {
        btnArr: ["add", "edit"],
        column: [
          {
            label: "所属单位",
            textAlign: "center",
            type: "dept",
            //level: "3",
            prop: "deptName",
            //propArr:"deptArr",
            idsStr: "deptId",
            //option:"deptOption",
            method: (data) => {},
          },
          {
            label: "人员名称",
            textAlign: "center",
            type: "user",
            prop: "name",
            //propArr:"userArr",
            idsStr: "account",
            //option: "userOption",
            method: (data) => {},
          },
          {
            label: "是否默认",
            textAlign: "center",
            type: "switch",
            prop: "defaultUser",
            method: (data) => {},
          },
        ],
        title: "",
        data: [],
        select: false,
        maxHeight: "100%",
        hideBtn: false,
        buttonArr: [
          {
            name: "删除",
            isShow: (row) => {
              return true;
            },
            methods: (row, index) => {
              this.preparaTable.data.splice(index, 1);
            },
          },
        ],
      },
    };
  },
  mounted() {
    this.init(this.userConfig);
  },
  watch: {
    userConfig:{
      handler(val) {
        this.init(val);
      }
    }
  },
  methods: {
    init(val) {
      let data = val ? JSON.parse(val) : [];
      this.$set(this.preparaTable, "data", data);
    },
    async getTableData() {
      let data = await this.$refs.preparaTable.getTableData();
      return JSON.stringify(data);
    },
  },
};
</script>

<style></style>
